/**
 * 设置localStorage
 * @param {string} key 
 * @param {any} value 
 */
export function setStorage(key: string, value: any) {
  localStorage.setItem(key, JSON.stringify(value));
}

/**
 * 获取localStorage
 * @param {string} key 
 * @returns {any}
 */
export function getStorage(key: string) {
  return JSON.parse(localStorage.getItem(key) || 'null');
}

export function formatTime(time: string, format = 'YYYY-MM-DD HH:mm:ss') {
  const date = new Date(time)
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()
  const padStart = (value: string, length: number) => value.padStart(length, '0')
  return format
    .replace('YYYY', `${year}`)
    .replace('MM', padStart(`${month}`, 2))
    .replace('DD', padStart(`${day}`, 2))
    .replace('HH', padStart(`${hour}`, 2))
    .replace('mm', padStart(`${minute}`, 2))
    .replace('ss', padStart(`${second}`, 2))
}